package cn.youframe.frame.service;

import cn.youframe.frame.base.BaseServiceImpl;
import cn.youframe.frame.beans.Menber;
import cn.youframe.frame.beans.YfDeptVO;
import cn.youframe.frame.beans.YfRoleVO;
import cn.youframe.frame.dao.LoginDao;
import cn.youframe.frame.exception.AppException;

import java.util.List;

/**
 * User: Administrator
 * DateTime: 12-7-22 下午1:04
 * Desc:
 */
public class LoginServiceImpl extends BaseServiceImpl implements LoginService {
    private LoginDao loginDao;

    public LoginDao getLoginDao() {
        return loginDao;
    }

    public void setLoginDao(LoginDao loginDao) {
        this.loginDao = loginDao;
    }

    @Override
    public Menber login(String account) {
        Menber menber=null;
        try{
            menber=loginDao.getMenber(account);
        }catch (Exception e){
            throw new AppException(e,"获取用户信息异常："+e.getMessage());
        }
        return menber;
    }
    @Override
    public YfDeptVO getDept(String did) {
        return loginDao.getDept(did);
    }

    @Override
    public List<YfRoleVO> getRoles(String uid) {
        return loginDao.getRoles(uid);
    }

    @Override
    public int addOnlineUser(Menber menber) {
        return loginDao.addOnlineUser(menber);
    }

    @Override
    public int delOnlineUser(String account) {
        return loginDao.delOnlineUser(account);
    }

    @Override
    public String userLogin(Menber menber) {
        String key;
        try {
            key=loginDao.userLogin(menber);
        }catch (Exception e){
            key=null;
            logger.error(e.getMessage(),e);
        }
        return key;
    }

    @Override
    public int userLogout(String key) {
        if(key==null ||key.equalsIgnoreCase("")){
            return -1;
        }
        return loginDao.userLogout(key);
    }
}
